package main

import (
	"github.com/go-redis/redis"
	"log"
	"time"
)

func main()  {
	option := &redis.Options{
		Addr:     "118.24.238.198:16379",
		Password: "",
		DB:       2,
	}
	redis1 := *redis.NewClient(option)
	n, err := redis1.Publish("test1","hello").Result()
	if nil != err{
		log.Print(err.Error())
	}
	log.Print(n)
	go func() {
		option := &redis.Options{
			Addr:     "118.24.238.198:16379",
			Password: "",
			DB:       2,
		}
		redis1 := *redis.NewClient(option)
		pubsub := redis1.PSubscribe("catchFishHall.topic.charge")
		defer pubsub.Close()
		for true  {
			msgi, err := pubsub.Receive()
			if err != nil {
				log.Print( err.Error())
			}
			switch msg := msgi.(type) {
			case *redis.Subscription:
				log.Print(nil, "got", msg.Kind, "on channel", msg.Channel)
				break
			case *redis.Message:
				log.Print( "Got message: ", msg.Payload)
			}
		}
	}()

	for true{
		time.Sleep(time.Second)
		n, err := redis1.Publish("catchFishHall.topic.charge","hello").Result()
		if nil != err{
			log.Print(err.Error())
			log.Print(n)
		}
	}
}

